package com.zhan.ielts.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.UUID;

public class StringUtil {
    public static String getCustumPara(String name) {
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("weixin.properties");
        Properties p = null;
        try {
            p = new Properties();
            p.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return p.getProperty(name);
    }

    public static String getUUIDRandom() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static String getStringFromDouble(String str) {
        if (str == null) {
            return str;
        }
        if (str.matches("\\d*?\\.0")) {
            str = str.split("\\.")[0];
        }
        return str;
    }

    public static String removeHeadAndTailEnter(String str) {
        if (str.startsWith("\n")) {
            str = str.substring(1);
        }
        if (str.endsWith("\n")) {
            str = str.substring(0, str.length() - 1);
        }
        if (!str.startsWith("\n") && !str.endsWith("\n")) {
            return str;
        }
        return removeHeadAndTailEnter(str);
    }

    public static void main(String[] args) {

        System.out.println(removeHeadAndTailEnter("\n\n\n1sdfsdfs.0\n"));
    }
}
